package com.hyc.myvideo.data.api;

import android.app.Activity;

import com.hyc.myvideo.data.api.constants.Constants;
import com.hyc.myvideo.utils.UserTokenCache;
import com.hyc.network.Api.HttpManagerApi;
import com.hyc.network.listener.HttpOnNextListener;

import java.io.File;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;

public class Api extends HttpManagerApi {
    String userToken = "";
    String userId = "";
    private Activity activity= null;
    public Api(HttpOnNextListener onNextListener, Activity appCompatActivity) {
        super(onNextListener, appCompatActivity);
        this.activity = appCompatActivity;
        /*统一设置*/
        setCache(false);
        userToken = UserTokenCache.USER_TOKEN.getValue(appCompatActivity);
        userId = UserTokenCache.USER_ID.getValue(appCompatActivity);
    }

    /***
     * 获取短信验证码
     * @param phone 手机号
     */
    public void requestPhoneCode(String phone) {
        setMethod(Constants.API_SMS);
        doHttpDeal(getRetrofit().create(HttpPostService.class).requestPhoneCode(phone));
    }


    /***
     * 第三方支付
     * @param payState 支付类型 1=充值,2=vip购买
     * @param payType  支付方式: alipay,wechat,unionpay
     * @param id
     */
    public void requestPay(int payState,String payType,String id) {
        setMethod(Constants.API_PAY);
        String  userToken = UserTokenCache.USER_TOKEN.getValue(activity);
        String userId = UserTokenCache.USER_ID.getValue(activity);
        doHttpDeal(getRetrofit().create(HttpPostService.class).requestPay(userId,userToken,payState,payType,id));
    }




    /***
     * 登录
     * @param user_phone    手机号
     * @param user_password 密码
     */
    public void userLogin(String user_phone, String user_password) {
        setMethod(Constants.API_LOGIN);
        doHttpDeal(getRetrofit().create(HttpPostService.class).requestLogin(user_phone, user_password));
    }

    /***
     * 第三方登录
     * @param uid     用户唯一标识
     * @param name    用户昵称
     * @param iconurl 用户头像
     * @param type    登录类型
     * @return
     */
    public void requestLoginTripartite(String uid, String name,String iconurl,int type) {
        setMethod(Constants.API_LOGIN_TRIPARTITE);
        doHttpDeal(getRetrofit().create(HttpPostService.class).requestLoginTripartite(uid, name,iconurl,type));
    }




    /***
     * 注册
     * @param user_phone    手机号
     * @param user_password 密码
     * @param code          验证码
     * @param invitation    邀请码
     */
    public void userRegistered(String user_phone, String user_password, String code,String invitation) {
        setMethod(Constants.API_REG);
        doHttpDeal(getRetrofit().create(HttpPostService.class).requestRegistered(user_phone, user_password, code, invitation));
    }


    /***
     * 请求用户信息
     */
    public void requestUserInfo() {
        setMethod(Constants.API_USERINFO);
        String  userToken = UserTokenCache.USER_TOKEN.getValue(activity);
        String userId = UserTokenCache.USER_ID.getValue(activity);
        doHttpDeal(getRetrofit().create(HttpPostService.class).requestUserInfo(userId, userToken));
    }

    /***
     * 修改昵称
     * @param nickname
     */
    public void userUpdataNickname(String nickname) {
        doHttpDeal(getRetrofit().create(HttpPostService.class).requestUpdataNickname(userId, userToken, nickname));
    }

    /***
     * 修改手机号
     * @param phone 手机号
     * @param code  验证码
     */
    public void userUpdataPhone(String phone, String code) {
        setMethod(Constants.API_USER_UPDATE_PHONE);
        doHttpDeal(getRetrofit().create(HttpPostService.class).requestUpdataPhone(userId, userToken, phone, code));
    }

    /***
     * 找回密码
     * @param phone   手机号
     * @param code    短信验证码
     * @param password 新密码
     * @param confirm_password 确认密码
     */
    public void updataPassword(String phone, String code,String password,String confirm_password) {
        setMethod(Constants.API_USER_PASSWPRD);
        doHttpDeal(getRetrofit().create(HttpPostService.class).requestUserPw(phone,code,password,confirm_password));
    }




    /***
     * 第三方登录 绑定手机号
     * @param phone 手机号
     * @param code  短信验证码
     * @param there_user_id 授权用户信息id
     * @return
     */
    public void requestBindPhone(String phone,String code,String there_user_id) {
        setMethod(Constants.API_USER_BIND_PHONE);
        doHttpDeal(getRetrofit().create(HttpPostService.class).requestBindPhone(phone, code, there_user_id));
    }




    /***
     * 上传头像
     * @param files
     */
    public void uploadFiles(File files) {
        // MediaType.parse("multipart/form-data")  | MediaType.parse("image/jpeg")
        RequestBody requestFile = RequestBody.create(MediaType.parse("image/jpeg"), files);
        MultipartBody.Part part = MultipartBody.Part.createFormData("user_face", files.getName(), requestFile);
        doHttpDeal(getRetrofit().create(HttpPostService.class).uploadFiles(RequestBody.create(null, userId), RequestBody.create(null, userToken), part));
    }

    /***
     * 购买VIP
     */
    public void userBuyVIP() {
        setMethod(Constants.API_USER_RECHARGE);
        doHttpDeal(getRetrofit().create(HttpPostService.class).requestVIP(userId, userToken));
    }

    /***
     * 充值露珠
     */
    public void userBuyDew() {
        setMethod(Constants.API_USER_RECHARGELIST);
        doHttpDeal(getRetrofit().create(HttpPostService.class).requestDew(userId, userToken));
    }

    /**
     * 意见反馈
     * @param content 反馈内容
     * @param contact 联系方式
     */
    public void userFeedback(String content,String contact) {
        doHttpDeal(getRetrofit().create(HttpPostService.class).requestFeedback(userId, userToken,content,contact));
    }

    /***
     * 我的评论
     * @param page 页数
     */
    public void requestCommentData(int page) {
        doHttpDeal(getRetrofit().create(HttpPostService.class).requestCommentData(userId, userToken,page));
    }

    /***
     * 我的报名
     * @param page 页数
     */
    public void requestRegisterData(int page) {
        doHttpDeal(getRetrofit().create(HttpPostService.class).requestRegisterData(userId, userToken,page));
    }

    /***
     * 我的优惠卷
     * @param page 页数
     */
    public void requestCouponData(int page) {
        doHttpDeal(getRetrofit().create(HttpPostService.class).requestCouponData(userId, userToken,page));
    }


    /***
     * 优惠卷转赠
     * @param user_bill_id 优惠卷id
     * @param phone     转赠人
     * @param count    转赠数量
     * @return
     */
    public void requestCouponDonated(String user_bill_id,String phone,String count){
        doHttpDeal(getRetrofit().create(HttpPostService.class).requestCouponDonated(userId, userToken,user_bill_id,phone,count));
    }

    /***
     * 我的关注列表
     * @param page 页数
     */
    public void requestFollowData(int page) {
        doHttpDeal(getRetrofit().create(HttpPostService.class).requestFollowData(userId, userToken,page));
    }

    /***
     * 我的课程
     * @param page  页数
     * @param state 0未完成,1已经完成
     */
    public void requestDirectData(int page,int state) {
        doHttpDeal(getRetrofit().create(HttpPostService.class).requestDirectData(userId, userToken,page,state));
    }

    /***
     * 我的课程详情列表
     * @param page  页数
     * @param d_id  课程id
     */
    public void requestDirectHourData(int page,String d_id) {
        doHttpDeal(getRetrofit().create(HttpPostService.class).requestDirectHourData(userId, userToken,page,d_id));
    }


    /***
     * 我的佣金
     */
    public void requestCommissionData() {
        doHttpDeal(getRetrofit().create(HttpPostService.class).requestCommissionData(userId, userToken));
    }
    /***
     * 我的佣金详情
     */
    public void requestCommissionDeiails(int page) {
        doHttpDeal(getRetrofit().create(HttpPostService.class).requestCommissionDeiailsData(userId, userToken,page));
    }

    /***
     * 统计-会员列表
     * @param page
     */
    public void requestStatisticsMember(int page) {
        doHttpDeal(getRetrofit().create(HttpPostService.class).requestStatisticsData(userId, userToken,page));
    }

    /***
     * 统计-提成列表
     * @param page
     */
    public void requestCommission(int page) {
        doHttpDeal(getRetrofit().create(HttpPostService.class).requestCommissionData(userId, userToken,page));
    }

    /***
     *我的购买
     * @param page
     */
    public void requestOrder(int page) {
        doHttpDeal(getRetrofit().create(HttpPostService.class).requestOrder(userId, userToken,page));
    }





    /**
     * 获取专栏列表
     */
    public void getColumnList(String column_type,int page) {
        setMethod(Constants.API_COLUMN);
        doHttpDeal(getRetrofit().create(HttpPostService.class).getColumnList(column_type,page));
    }

    /**
     * 获取专栏详情
     */
    public void getColumnDetails(String column_id) {
        setCache(true);
        setMethod(Constants.API_COLUMN_DETAILS);
        doHttpDeal(getRetrofit().create(HttpPostService.class).getColumnDetails(column_id));
    }

    /**
     *  专栏详情 报名
     * @param column_id
     */
    public void postColumnSignUp(String column_id,String user_id) {
        setMethod(Constants.API_COLUMN_ENROLL);
        doHttpDeal(getRetrofit().create(HttpPostService.class).postColumnSignUp(user_id,column_id));
    }

    /**
     * 获取首页数据
     */
    public void getHomeList() {
        setCache(true);
        doHttpDeal(getRetrofit().create(HttpPostService.class).getHomeList());
    }

  /**
   * 获取推荐课程列表
   */
  public void getHomeClassList(String curriculum_class_id, int page,
      String curriculum_charge_state) {
    setMethod(Constants.API_CURRICULUM);
    doHttpDeal(getRetrofit().create(HttpPostService.class).getHomeClassList(curriculum_class_id, page, curriculum_charge_state));
  }

  /**
   * 获取系列列表
   * @param curriculum_id id
   */
  public void getHomeClassHourList(String curriculum_id) {
    setMethod(Constants.API_CURRICULUM);
    doHttpDeal(getRetrofit().create(HttpPostService.class).getHomeClassHourList(curriculum_id));
  }

  /**
   * 课时详情
   * @param curriculum_hour_id id
   */
  public void getHomeClassHourDetails(String curriculum_hour_id) {
    setMethod(Constants.API_CURRICULUM_HOUR_DETAILS);
    doHttpDeal(getRetrofit().create(HttpPostService.class).getHomeClassHourDetails(curriculum_hour_id));
  }

  /**
   * 课时详情 评论列表
   * @param curriculum_hour_id id
   * @param page page
   */
  public void getHomeClassHourCommentList(String curriculum_hour_id,int page) {
    setMethod(Constants.API_CURRICULUM_HOUR_COMMENT_LIST);
    doHttpDeal(getRetrofit().create(HttpPostService.class).getHomeClassHourCommentList(curriculum_hour_id,page));
  }

    /**
     *  课时详情 发布评论
     * @param curriculum_hour_id
     * @param comment_content
     */
  public void publishClassComment(String user_id,String curriculum_hour_id,String comment_content) {
    setMethod(Constants.API_SET_CURRICULUM_HOUR);
    doHttpDeal(getRetrofit().create(HttpPostService.class).publishClassComment(user_id,curriculum_hour_id,comment_content));
  }

    /**
     *  课时记录添加
     * @param user_id
     * @param curriculum_hour_id
     * @param practice_record_hour
     */
  public void setUserPracticeRecord(String user_id,String curriculum_hour_id,String practice_record_hour) {
    setMethod(Constants.API_PRACTICE_SET_USER_PRACTICE_RECORD);
    doHttpDeal(getRetrofit().create(HttpPostService.class).setUserPracticeRecord(user_id,curriculum_hour_id,practice_record_hour));
  }

    /**
     * 获取修炼目录
     * @param user_id
     */
  public void getPracticeList(String user_id) {
    setMethod(Constants.API_PRACTICE);
    doHttpDeal(getRetrofit().create(HttpPostService.class).getPracticeList(user_id));
  }

  /**
   * 修炼目录 添加目录
   * @param user_id
   * @param catelog_name
   */
  public void setPracticeCatalog(String user_id,String catelog_name) {
    setMethod(Constants.API_PRACTICE_SET_PRACTICE_CATELOG);
    doHttpDeal(getRetrofit().create(HttpPostService.class).setPracticeCatalog(user_id,catelog_name));
  }

  /**
   * 获取修炼记录
   * @param user_id
   * @param page
   */
  public void getPracticeRecord(String user_id,int page) {
    setMethod(Constants.API_PRACTICE_RECORD);
    doHttpDeal(getRetrofit().create(HttpPostService.class).getPracticeRecord(user_id,page));
  }

  /**
   * 修炼目录 添加课程
   * @param user_id
   * @param catelog_id
   * @param curriculum_id
   */
  public void setPracticeCatelogCurriculum(String user_id,String catelog_id,String curriculum_id) {
    setMethod(Constants.API_PRACTICE_SET_CATELOG_CURRICULUM);
    doHttpDeal(getRetrofit().create(HttpPostService.class).setPracticeCatelogCurriculum(user_id,catelog_id,curriculum_id));
  }

  /**
   * 修炼目录 课程列表
   * @param user_id
   * @param catelog_id
   * @param page
   */
  public void getPracticeCatelogCurriculumList(String user_id,String catelog_id,int page) {
    setMethod(Constants.API_PRACTICE_CATELOG_CURRICULUM_LIST);
    doHttpDeal(getRetrofit().create(HttpPostService.class).getPracticeCatelogCurriculumList(user_id,catelog_id,page));
  }

  /**
   * 购买详情
   * @param user_id
   * @param parame_id
   * @param pay_state
   */
  public void getPayDetails(String user_id,String parame_id,int pay_state) {
    setMethod(Constants.API_PAY_DETAILS);
    doHttpDeal(getRetrofit().create(HttpPostService.class).getPayDetails(user_id,parame_id,pay_state));
  }

}
